<?php      
header("Content-Type:text/html;charset=utf-8");//防止网页中文乱码
session_start();
   if (isset($_SESSION['userinfo']))
   {
       $login=true;
       $userinfo=$_SESSION['userinfo'];
   }
    else {
    echo "<script language='javascript'>";
    echo "alert('您还没登录，请先登录！');";
    echo "window.location.href='login.php';";
    echo "</script>";
    die;
   }
   
   
  
    require 'dbcon.php';
   $search=(isset($_GET['search']))?$_GET['search']:"";
    $pagesize=5;//决定了每页显示几条留言
    $sql="select * from tb_note where username like '%{$search}%'or content like '%{$search}%'";
    $result=$db->query($sql);  
    $total=$result->num_rows;     
    $maxpage=ceil($total/$pagesize);
    $page=(isset($_GET['page']))?$_GET['page']:1;  
    $page=($page<=0)?1:$page;   
    $page=($page>$maxpage)?$maxpage:$page;   
    $first=($page-1)*$pagesize;
    $first=($first<0)?0:$first;//数据库没有留言时加
    //调试时用
    //echo    $page;
    //exit;      
    
   $sql="select * from tb_note where username  like  '%{$search}%' or content like '%{$search}%' order by id desc limit  {$first},{$pagesize}";//留言的时间顺序
   $result=$db->query($sql);  //结果集    不利用我们使用，结果集--》数组
    $sum=$result->num_rows;  //计算有多少条留言
   $wishlist=$result->fetch_all(MYSQLI_BOTH);   //将结果集转化为二维数组,MYSQLI_NUM 索引数组默认   $bbslist[1][2] 关联数组MYSQLI_ASSOC  两者都有MYSQLI_BOTH)   
   require 'list_html.php';
    
   $result->free();
   $db->close();
